
use  "$data/clean/vignette.dta", clear

 *** Summary statistics ***


tempfile main
save `main', replace

clear all
eststo clear
estimates drop _all

loc columns = 6

set obs 10
gen x = 1
gen y = 1

forval i = 1/`columns' {
	eststo col`i': reg x y
} 

loc count = 1

loc statnames ""
loc varlabels ""

/* Custom fill cells */



use `main', clear


gen pana=.
gen empt =. 


label var pana "\underline{Individual level characteristics} " 

label var empt " "
  
  foreach yvar of varlist pana empt male age vocational tertiary employed student retired member  {
	qui sum `yvar', d
	if `r(N)'!=0 {
	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col1
	cap: estadd loc thisstat`count' = string(`r(sd)', "%9.2f"): col2
	cap: estadd loc thisstat`count' = string(`r(p50)', "%9.2f"): col3
	cap: estadd loc thisstat`count' = string(`r(min)', "%9.0f"): col4
	cap: estadd loc thisstat`count' = string(`r(max)', "%9.0f"): col5
	cap: estadd loc thisstat`count' = `r(N)' : col6 
	}

	/* Row Labels */
	
	loc thisvarlabel: variable label `yvar'
	local varlabels "`varlabels' "`thisvarlabel'" "
	loc statnames "`statnames' thisstat`count'"
	loc count = `count' + 1

}


/* Footnotes */

loc prehead "\begin{tabular}{l*{`columns'}{c}} \toprule"

loc postfoot "\bottomrule \end{tabular}"


esttab col* using "$output/sumstats_vignette", booktabs cells(none) nonum nogap mtitle("Mean" "SD" "Median" "Min." "Max." "Obs.") ///
 stats(`statnames', labels(`varlabels'))  prehead("`prehead'") postfoot("`postfoot'") compress wrap replace

eststo clear
